package service

import (
	"cabinet/model"
	"cabinet/pkg/global"
	"cabinet/serializer"
	"github.com/gin-gonic/gin"
)

// UserLoginService 管理用户登录的服务
type UserLoginService struct {
	UserName string `form:"user_name" json:"user_name" binding:"required,min=5,max=30"`
	Password string `form:"password" json:"password" binding:"required,min=8,max=40"`
	Token    bool   `form:"token" json:"token"`
}

// Login 用户登录函数
func (service *UserLoginService) Login(c *gin.Context) serializer.Response {
	var user model.UserInfo

	if err := global.Mysql.Where("user_name = ?", service.UserName).First(&user).Error; err != nil {
		return serializer.ParamErr("账号或密码错误", nil)
	}

	//var token string
	//var tokenExpire int64
	//var err error
	//token, tokenExpire, err = util.GenerateToken(int(user.ID))
	//if err != nil {
	//	return serializer.DBErr("redis err", err)
	//}

	//data := serializer.BuildUser(user)
	//data.Token = token
	//data.TokenExpire = tokenExpire
	return serializer.Success("")
}
